package cn.iocoder.yudao.module.wms.dal.mysql.person;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.wms.controller.admin.person.vo.PersonPageReqVO;
import cn.iocoder.yudao.module.wms.controller.admin.person.vo.PersonSaveReqVO;
import cn.iocoder.yudao.module.wms.dal.dataobject.person.PersonDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

/**
 * 业务员档案 Mapper
 *
 * @author 孙广伟
 */
@Mapper
public interface PersonMapper extends BaseMapperX<PersonDO> {

    default PageResult<PersonDO> selectPage(PersonPageReqVO reqVO, Collection<Long> deptIds) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PersonDO>()
                .inIfPresent(PersonDO::getDeptId, deptIds)
                .likeIfPresent(PersonDO::getCode, reqVO.getCode())
                .likeIfPresent(PersonDO::getName, reqVO.getName())
                .eqIfPresent(PersonDO::getSex, reqVO.getSex())
                .betweenIfPresent(PersonDO::getBirthday, reqVO.getBirthday())
                .betweenIfPresent(PersonDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PersonDO::getId));
    }

    default Long selectCountByCode(PersonSaveReqVO reqVO) {
        return selectCount(new LambdaQueryWrapperX<PersonDO>()
                .eqIfPresent(PersonDO::getCode, reqVO.getCode())
                .neIfPresent(PersonDO::getId, reqVO.getId()));
    }

    List<PersonDO> getPersonList(PersonDO personDO);
}